import React from 'react';
import ReactDOM from 'react-dom';
import store from './store/index.js'
import { add } from './store/action'
class App extends React.Component {
  componentDidMount() {
    // store.subscribe 执行结果是一个小函数  这个小函数执行的时候 
    // 会把这次添加的回调函属，从对应事件池中移除
    this.clear = store.subscribe(() => {
      console.log("更新视图")
      this.setState({})
    })
    this.clear2 = store.subscribe(() => {
      console.log("666")

    })
    this.clear3 = store.subscribe(() => {
      console.log("888")
    })

    setTimeout(() => {
      this.clear2()
    }, 5000);
  }
  render() {
    console.log(store.dispatch)
    let { QQQ, WWW } = store.getState()
    return <div className=''>
      <h1 style={{ color: WWW.color }}>
        {QQQ.count}
      </h1>
      <button onClick={() => {
        store.dispatch(add())
        // setTimeout(() => {
        //   store.dispatch(add())
        // }, 2000);
      }}>+</button>
    </div>;
  }
}

ReactDOM.render(<App />, document.getElementById('root'))